<?php

use yii\helpers\Html;
use yii\grid\GridView;

/* @var $this yii\web\View */
/* @var $searchModel app\models\search\AsrCustomerSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = '所属列表名称：'.\app\models\AsrMobile::findOne($_GET['mobile_id'])->listname;
$this->params['breadcrumbs'][] = ['label' => '电话号码列表', 'url' => ['asr-mobile/index']];
$this->params['breadcrumbs'][] = ['label' => '所属电话号码列表'];
?>
<div class="asr-customer-index">
    <a id="back" class="btn btn-default pull-left" href="../asr-mobile/index" ><i class="fa fa-backward"></i> 返回</a><br><br>

    <p>
        <?= Html::a('添加号码', ['create?mobile_id='.$_GET['mobile_id']], ['class' => 'btn btn-info fa fa-plus']) ?>
    </p>

    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'showFooter' => true,
        'columns' => [
            ['class' => 'yii\grid\SerialColumn'],

            [   
                'attribute'=>'username',
                'footer' => '
                    <input id="num" class="btn btn-default btn-xs btn-delete" placeholder="每页显示的条数" onkeyup="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,\'\')}else{this.value=this.value.replace(/\D/g,\'\')}" onafterpaste="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,\'\')}else{this.value=this.value.replace(/\D/g,\'\')}">
                ',
                'value'=>function($model){
                    return $model->username;
                }
            ],
            'phone_num',
            'company_name',
            'job',
            'address',
            ['attribute' => 'remark',
                'value'=>
                    function($model){
                        if ($model->remark!=null){
                            return  $model->remark;
                        }else{
                            return  "";
                        }
                    },
            ],
            ['attribute' => 'sex',
                'value'=>
                    function($model){
                        if ($model->sex==1){
                            return  "男";
                        }else{
                            return  "女";
                        }
                    },
            ],

            ['class' => 'yii\grid\ActionColumn',//下面是新增加的按按钮
                'header'=>'操作',
                'template' => ' {update}&nbsp;&nbsp;&nbsp;{delete} ',
                'buttons' => [
                    'update' => function ( $url,$model) {
                        return  '<a href="'.$url.'&mobile_id='.$_GET['mobile_id'].'" class="btn btn-info fa fa-edit">修改</a>';
                    },
                    'delete' => function ( $url,$model) {
                        return  '<a href="'.$url.'&mobile_id='.$_GET['mobile_id'].'" title="删除" aria-label="删除" data-pjax="0" data-confirm="您确定要删除此项吗？" data-method="post"><span class="btn btn-danger fa fa-remove">删除</span></a>';
                    },
                ],
                'options'=>[
                    'width'=>'20%',
                ],
                'footerOptions' => ['colspan' => 1],  //设置删除按钮垮列显示；
            ]
        ],
        'filterModel' => $searchModel,
        'showFooter' => true,  //设置显示最下面的footer
        'pager'=>[
            'firstPageLabel'=>"第一页",
            'lastPageLabel'=>'最后一页',
        ],
    ]); ?>
</div>
<script type="text/javascript">
    $('#num').focusout(function () {//当鼠标失去焦点是触发事件,实现用户自定义分页
        var url = "<?= 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] ?>";
        $.ajax({
            type: 'post',
            async: true,
            url: url,
            data: {pageSize: $("#num").val()},
            success: function (data) {
                window.location.reload();
            },
            error: function (error) {

            }
        });
    })
</script>
